package com.tensquare.usercrawler.task;

import com.tensquare.usercrawler.dao.UserDao;
import com.tensquare.usercrawler.pipeline.UserDbPipeline;
import com.tensquare.usercrawler.processor.UserProceesor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;
import us.codecraft.webmagic.Spider;
import us.codecraft.webmagic.scheduler.RedisScheduler;

/**
 * 用户爬取任务类
 */
@Component
public class UserTask {

    @Autowired
    private UserProceesor userProceesor;

    @Autowired
    private UserDbPipeline userDbPipeline;

    @Autowired
    private RedisScheduler redisScheduler;

    /**
     * 用户爬取
     */
    @Scheduled(cron = "40 12 12 * * ?")
    public void userTask(){
        Spider spider = Spider.create(userProceesor)
                .addUrl("https://blog.csdn.net/")
                .addPipeline(userDbPipeline)
                .setScheduler(redisScheduler);

        spider.start();


    }

}
